<html>
<head><meta charset="utf-8"><title>check if mir::Body is a Drop method? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/check.20if.20mir.3A.3ABody.20is.20a.20Drop.20method.3F.html">check if mir::Body is a Drop method?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="234731574"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/check%20if%20mir%3A%3ABody%20is%20a%20Drop%20method%3F/near/234731574" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Hughes <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/check.20if.20mir.3A.3ABody.20is.20a.20Drop.20method.3F.html#234731574">(Apr 15 2021 at 18:48)</a>:</h4>
<p>Hi, is there an easy way to check if a MIR <code>Body&lt;'tcx&gt;</code> refers to the <code>fn drop(&amp;mut self)</code> method in the <code>Drop</code> trait?</p>
<p>In my custom rustc fork, i'd like to add a MIR pass that does some additional validation on each drop method as a MIR transform.</p>



<a name="234736274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/check%20if%20mir%3A%3ABody%20is%20a%20Drop%20method%3F/near/234736274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/check.20if.20mir.3A.3ABody.20is.20a.20Drop.20method.3F.html#234736274">(Apr 15 2021 at 19:19)</a>:</h4>
<p>You can, by going through <code>MirSource</code> and <code>InstanceDef</code> to get the original <code>DefId</code></p>



<a name="234736331"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/check%20if%20mir%3A%3ABody%20is%20a%20Drop%20method%3F/near/234736331" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/check.20if.20mir.3A.3ABody.20is.20a.20Drop.20method.3F.html#234736331">(Apr 15 2021 at 19:19)</a>:</h4>
<p>Ah, <code>MirSource</code> has a <code>def_id</code> method too</p>



<a name="234738484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/check%20if%20mir%3A%3ABody%20is%20a%20Drop%20method%3F/near/234738484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Hughes <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/check.20if.20mir.3A.3ABody.20is.20a.20Drop.20method.3F.html#234738484">(Apr 15 2021 at 19:32)</a>:</h4>
<p><span class="user-mention" data-user-id="211727">@Jonas Schievink  [he/him]</span> Thanks! Once I find the original <code>DefId</code> how do I check that it refers to the drop function though?</p>



<a name="234739579"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/check%20if%20mir%3A%3ABody%20is%20a%20Drop%20method%3F/near/234739579" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/check.20if.20mir.3A.3ABody.20is.20a.20Drop.20method.3F.html#234739579">(Apr 15 2021 at 19:38)</a>:</h4>
<p>I <em>think</em> you can call the <code>trait_of_item</code> query and compare the result against the <code>Drop</code> lang item</p>



<a name="234740754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/check%20if%20mir%3A%3ABody%20is%20a%20Drop%20method%3F/near/234740754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Hughes <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/check.20if.20mir.3A.3ABody.20is.20a.20Drop.20method.3F.html#234740754">(Apr 15 2021 at 19:45)</a>:</h4>
<p>Aha, that makes sense. Thanks, I'll give this a try :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>